<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../js/layui/css/layui.css"  media="all">
</head>
<body>
 
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
	<button class="layui-btn layui-btn-sm" lay-event="sendMaster">派单</button>
  </div>
</script>

          
<script src="../js/layui/layui.js" charset="utf-8"></script>
<script>
var order = window.parent.order; 
layui.use(['table','jquery'], function(){
  var table = layui.table
  ,$ = layui.jquery;
  table.render({
    elem: '#test'
    ,height: 'full'
    ,url:'../master/selectList'
    ,method:'post'
    ,toolbar: '#toolbarDemo'
    ,title: '用户数据表'
    ,cellMinWidth: 80
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'id', title:'工号'}
      ,{field:'name', title:'姓名', edit: 'text'}
      ,{field:'address', title:'位置'}
      ,{field:'status', title:'状态',templet:status}
    ]]
    ,page: true
  });
  //工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'sendMaster':
       	var data = checkStatus.data;
	    if(data.length!=1){
	    	layer.msg("一次只能指派一个订单！");
	    	return false;
	    }else{
	    	$.post("/SSMR/order/sendMaster",{"mid":data[0].id,"id":order.id},function(data){
	    		if(data == '1'){
	    			layer.msg("派单成功！");
	    			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		            parent.layer.close(index); 
		            window.parent.location.reload();
	    		}
	    	});
	    }
      	break;        
    };
  });
});
function status(d){
	var str="";
	if(d.status=='0'){
		str="在忙";
	}
	if(d.status=='1'){
		str="空闲";
	}
	if(d.status=='2'){
		str="其他";
	}
	return str;
}
</script>
</body>
</html>